<!--
 @description 经销商档案新建-报图情况
 @fileName ReportPic.vue
 @author zengqiongying
 @created 2023/04/30 18:08:14
-->
<template>
  <div class="has-foot-pb">
    <Card no-mg :round="false">
      <!-- <Cell title="是否报图" custom :right="false" required>
        <qmp-switch v-model="formData.isReportPic">
          <template #background>
            <span class="qmp-switch__background"> {{ formData.isReportPic ? '是' : '否' }}</span>
          </template>
        </qmp-switch>
      </Cell> -->

      <FieldSelect
        v-model="formData.isReportPic"
        title="是否报图"
        :url="`/data-dict/app/v2/dictionary/BOOLEANS`"
        label-name="dictName"
        value-name="dictCode"
        method="get"
        :params="{ query: { appCode: 'slm', domainCode: 'marketing' }, type: 0 }"
        required
      />
      <Cell
        title="特殊建档附件"
        sub-title="(如未报图/未交保证金等情况，业务请示申请审核通过的流程附件)"
        is-column
        custom
        :right="false"
      >
        <AttachmentUpload v-model="attrFileList" type-code="ACCESS057" :objectId="shopDetail.id" />
      </Cell>
    </Card>

    <div :class="['ctm-content-foot', { relative: keyboard.show }]">
      <div class="btn radius-larg ctm-btn-main" @click="onSave()">保存</div>
    </div>
  </div>
</template>

<script lang="ts">
  import { reactive, toRefs, getCurrentInstance, nextTick, computed } from 'vue'
  import { useRouter, useRoute } from 'vue-router'
  import Card from '@/components/Card/index.vue'
  import Cell from '@/components/Cell/index.vue'
  import FieldSelect from '@/components/FieldSelect/index.vue'
  import AttachmentUpload from '@/components/AttachmentUpload/index.vue'
  import { detail } from '@/apis/dealerMarketing/NewArchive'
  import { shopReportPicMixin, getAttachmentList } from '../mixins/Shop'
  import GetKeyboardMixin from '@/utils/useKeyboard'

  export default {
    name: 'DealerNewArchiveReportPic',
    components: {
      Card,
      Cell,
      AttachmentUpload,
      FieldSelect
    },
    setup() {
      const { proxy }: any = getCurrentInstance()
      const $router = useRouter()
      const $route = useRoute()
      const { datas, shopDetail, onSave } = shopReportPicMixin(() => {
        proxy.$SimpleEvents.emit('refreshCustomerNewArchiveEditInfo', datas.id)
        nextTick(() => {
          $router.goBack()
        })
      })
      datas.id = $route.query.id || ''
      datas.keyboard = {
        show: false
      }
      datas.keyboard = GetKeyboardMixin()

      const getDetail = () => {
        const id = `${datas.id}`
        detail(id).then(async (res: any) => {
          const d = res.data?.shopDTO || {}
          datas.detail = res.data || {}
          datas.formData = {
            isReportPic: d.isReportPic //[1, '1'].includes(d.isReportPic)
          }
          if (d.id) {
            datas.otherFiles = await getAttachmentList(d.id, ['ACCESS057'])
          }
        })
      }

      getDetail()

      return {
        ...toRefs(datas),
        shopDetail,
        onSave
      }
    }
  }
</script>
<style lang="less" scoped></style>
